package com.yadang.infra.service;

import com.yadang.infra.bean.CmmDictType;
import com.yadang.infra.mapper.CmmDictTypeMapper;
import com.yadang.infra.tools.SnowFlakeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.invoke.MethodHandles;
import java.util.Date;
import java.util.List;

@Service
public class CmmDictTypeService {
    private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

    @Autowired
    private CmmDictTypeMapper cmmDictTypeMapper;

    public void insertDictType(String type, String desc) {

        CmmDictType cmmDictType = new CmmDictType();
        cmmDictType.setId(SnowFlakeUtil.getId());
        cmmDictType.setType(type);
        cmmDictType.setTypeDesc(desc);
        cmmDictType.setCreateDate(new Date());
        cmmDictType.setUpdateDate(new Date());

        try {
            int count = cmmDictTypeMapper.insert(cmmDictType);
        } catch (Exception e) {
            LOGGER.error("字典类型新增失败", e);
            throw new RuntimeException(e);
        }

    }

    public List<CmmDictType> selectAllType() {
        List<CmmDictType> cmmDictTypeList = cmmDictTypeMapper.selectAllType();
        return cmmDictTypeList;
    }

    public CmmDictType selectOneType(String cmmDictType) {
        return cmmDictTypeMapper.selectType(cmmDictType);
    }
}
